package cn.tedu.stage2.day05;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 改正下面程序的错误
 *
 * 向文件testpw.txt中以UTF-8编码写入一行字符串：
 * 你好!我喜欢java!
 */
public class Test01 {
    public static void main(String[] args) {
        try {
            FileOutputStream fos = new FileOutputStream("testpw.txt");
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            String line = "你好!我喜欢java!";
            byte[] data = line.getBytes(StandardCharsets.UTF_8);
            bos.write(data);
            bos.flush();
            System.out.println("写出完毕!");
            bos.close();
        }catch(Exception e) {
            System.out.println("出错了!");
        }
    }
}
